﻿$(function () {
    //初始化控件
    laydate.render({ elem: '#txtshowillTime', type: 'datetime' });
    laydate.render({ elem: '#txthelpTime', type: 'datetime' });
    laydate.render({ elem: '#txthoscarreadyTime', type: 'datetime' });
    laydate.render({ elem: '#txthoscargoTime', type: 'datetime' });
    laydate.render({ elem: '#txthoscaraddrTime', type: 'datetime' });
    laydate.render({ elem: '#txthoscarleaveTime', type: 'datetime' });
    laydate.render({ elem: '#txthoscarbackTime', type: 'datetime' });
    laydate.render({ elem: '#txtpaddrTime', type: 'datetime' });
    laydate.render({ elem: '#txtnwithpTime', type: 'datetime' });
    laydate.render({ elem: '#txtgetbloodTime', type: 'datetime' });
    laydate.render({ elem: '#txtbloodtochkTime', type: 'datetime' });
    laydate.render({ elem: '#txtbloodchkedTime', type: 'datetime' });
    laydate.render({ elem: '#txtecgchkedTime', type: 'datetime' });
    laydate.render({ elem: '#txtopentickctTime', type: 'datetime' });
    laydate.render({ elem: '#txtpreshowillTime', type: 'datetime' });
    laydate.render({ elem: '#txtattrCtMriTime', type: 'datetime' });
    laydate.render({ elem: '#txtctMrichkedTime', type: 'datetime' });
    laydate.render({ elem: '#txtctMriReportTime', type: 'datetime' });
    laydate.render({ elem: '#txtbloodcheckTime', type: 'datetime' });
    laydate.render({ elem: '#txtnbloodcheckTime', type: 'datetime' });
    laydate.render({ elem: '#txtsandjzchkTime', type: 'datetime' });
    laydate.render({ elem: '#txtrsDocwithpTime', type: 'datetime' });
    laydate.render({ elem: '#txtDoctallTime', type: 'datetime' });
    laydate.render({ elem: '#txtfamilysignTime', type: 'datetime' });
    laydate.render({ elem: '#txtpaddredrsRoomTime', type: 'datetime' });
    laydate.render({ elem: '#txtfirstgyTime', type: 'datetime' });
    laydate.render({ elem: '#txtjmrs24hnzfslncxTime', type: 'datetime' });
    laydate.render({ elem: '#txtjrzltallTime', type: 'datetime' });
    laydate.render({ elem: '#txtjrzlfamilySignTime', type: 'datetime' });
    laydate.render({ elem: '#txtptodgRoomedTime', type: 'datetime' });
    laydate.render({ elem: '#txtfinisheddmccTime', type: 'datetime' });
    laydate.render({ elem: '#txtfinishedzypgTime', type: 'datetime' });
    laydate.render({ elem: '#txtfristbloodaginTime', type: 'datetime' });
    laydate.render({ elem: '#txtpleavedgRoomTime', type: 'datetime' });
    laydate.render({ elem: '#txtxgnjrzl24hnzfslncxTime', type: 'datetime' });
    laydate.render({ elem: '#txtturnBackTime', type: 'datetime' });
    position();
    SetValue();
    $("#btnSave").on("click", function () { savemr(); });
    $("#btnBack").on("click", function () { window.history.back(); });
});
function position() {
    LiftEffect({
        "control1": ".lift-nav",
        "control2": ".lift",
        "target": [".t0", ".t1"],
        "current": "current"
    });
}
function printmr() {
    if ($("#txtPatientId").val() == "") return;
    window.parent.top.tab.addTabItem({ tabid: "print" + $("#txtPatientId").val(), text: "病历-" + $("#txtrealName").val(), url: "/TraumaCenter/MedicalRecords/TimeLinePrint?pid=" + $("#txtPatientId").val() });
}
function savemr() {
    if ($("#txtPatientId").val() == "") return;
    var data = {};
    $.each(FiledArray, function (i, a) {
        var datadetail = {};
        $.each(a.column, function (j, b) {
            var str = "";
            if (b.type == "text" || b.type == 'date') {
                str = $('#' + b.code).val();
            } else if (b.type == "radio") {
                str = $("input[name='" + b.code + "']:checked").val();
            } else if (b.type == "checkbox") {
                var str = CheckBoxToArrStr(b.code);
            }
            datadetail[b.tocode] = str == "" ? b.value : str;
        })
        data[a.table] = datadetail;
    })
    $.post("/TraumaCenter/MedicalRecords/SetExecutionDate", { datajson: JSON.stringify(data), rd: getRnd() }, function (data, textStatus) {
        if (textStatus == "success") {
            var d = $.parseJSON(data);
            if (d.Result == 1) {
                $.ligerDialog.success("保存成功");
            }
            else if (d.Result == 0) {
                $.ligerDialog.error(d.Body);
            }
            else {
                $.ligerDialog.error("程序错误");
            }
        }
    })
}
function SetValue() {
    var patientid = $('#txtPatientId').val();
    if (!IsEmpty(patientid)) {
        $.ajax({
            url: '/TraumaCenter/MedicalRecords/Get_PatientTimePath?patientid=' + patientid + '&r=' + getRnd(),
            cache: false,
            dataType: 'json',
            success: function (data) {
                $.each(FiledArray, function (i, a) {
                    var datadetail = eval("data." + a.table);
                    if (datadetail != undefined && datadetail != null) {
                        $.each(a.column, function (j, b) {
                            if (b.type == "text") {
                                $('#' + b.code).val(eval("datadetail." + b.tocode));
                            } else if (b.type == "date") {
                                $('#' + b.code).val(obj2Timemm(eval("datadetail." + b.tocode)));
                            } else if (b.type == "radio") {
                                $("input[name='" + b.code + "'][value='" + eval("datadetail." + b.tocode) + "']").attr("checked", true);
                            } else if (b.type == "checkbox") {
                                CheckBoxSetVal(b.code, eval("datadetail." + b.tocode), false);
                            }
                        })
                    }
                })
            }
        });
    } else {
        $.ligerDialog.error("获取数据失败！");
    }
}
var FiledArray = [
    {
        table: "patientInfo",
        column: [
            { name: "ID", code: "txtPIId", tocode: "ID", value: "0", type: "text" },
            { name: "呼救时间", code: "txthelpTime", tocode: "HelpTime", value: "", type: "date" },
            { name: "急诊护士接诊患者时间", code: "txtnwithpTime", tocode: "H_MEDICAL_TIME", value: "", type: "date" },
            { name: "转归时间", code: "txtturnBackTime", tocode: "LeaveHospitalTime", value: "", type: "date" },
        ]
    },
    {
        table: "ambulanceInfo",
        column: [
            { name: "ID", code: "txtAIId", tocode: "ID", value: "0", type: "text" },
            { name: "PatientId", code: "txtPatientId", tocode: "PATIENT_ID", value: "0", type: "text" },
            { name: "发病时间", code: "txtshowillTime", tocode: "EMS_DISEASE_TIME", value: "", type: "date" },
            { name: "120到达现场时间", code: "txthoscaraddrTime", tocode: "EMS_ARRIVE_TIME", value: "", type: "date" },
            { name: "患者到达医院时间", code: "txtpaddrTime", tocode: "EMS_ARRIVEDOOR_TIME", value: "", type: "date" },
            { name: "采血时间", code: "txtgetbloodTime", tocode: "Troponin_Blood_Time", value: "", type: "date" },
        ]
    },
    {
        table: "patientTimePath",
        column: [
            { name: "Id", code: "txtTPId", tocode: "Id", value: "0", type: "text" },
            { name: "PatientId", code: "txtPatientId", tocode: "PATIENT_ID", value: "0", type: "text" },
            { name: "120派车时间", code: "txthoscarreadyTime", tocode: "AmbulanceArriveTime", value: "", type: "date" },
            { name: "120出车时间", code: "txthoscargoTime", tocode: "AmbulanceDriveOutTime", value: "", type: "date" },
            { name: "120离开现场时间", code: "txthoscarleaveTime", tocode: "AmbulanceLeaveTime", value: "", type: "date" },
            { name: "送检时间", code: "txtbloodtochkTime", tocode: "InspectionTime", value: "", type: "date" },
            { name: "血糖检测完成时间", code: "txtbloodchkedTime", tocode: "BloodSugarTestTime", value: "", type: "date" },
            { name: "心电图检测完成时间", code: "txtecgchkedTime", tocode: "ElectrocardiogramTestTime", value: "", type: "date" },
            { name: "开具头颅CT单时间", code: "txtopentickctTime", tocode: "CTOpenBillTime", value: "", type: "date" },
            { name: "发病时间（最后表现正常时间）", code: "txtpreshowillTime", tocode: "OnsetTime", value: "", type: "date" },
            { name: "患者到达CT/MRI室时间", code: "txtattrCtMriTime", tocode: "ArriveCTTime", value: "", type: "date" },
            { name: "CT/MRI检查结束时间", code: "txtctMrichkedTime", tocode: "CTTestEndTime", value: "", type: "date" },
            { name: "CT/MRI报告时间", code: "txtctMriReportTime", tocode: "CTTestReportTime", value: "", type: "date" },
            { name: "血常规检验时间", code: "txtbloodcheckTime", tocode: "CBCTestTime", value: "", type: "date" },
            { name: "凝血常规检验时间", code: "txtnbloodcheckTime", tocode: "CoagulationTestTime", value: "", type: "date" },
            { name: "肾功能及电解质检验时间", code: "txtsandjzchkTime", tocode: "RenalTestTime", value: "", type: "date" },
            { name: "溶栓医生接诊患者时间", code: "txtrsDocwithpTime", tocode: "ThrombolysisReceptionTime", value: "", type: "date" },
            { name: "静脉溶栓开始谈话时间", code: "txtDoctallTime", tocode: "ThrombolysisTalkTime", value: "", type: "date" },
            { name: "静脉溶栓家属签字时间", code: "txtfamilysignTime", tocode: "ThrombolysisSignTime", value: "", type: "date" },
            { name: "患者到达溶栓室时间", code: "txtpaddredrsRoomTime", tocode: "ThrombolysisArriveTime", value: "", type: "date" },
            { name: "首剂给药时间", code: "txtfirstgyTime", tocode: "FirstAdministrationTime", value: "", type: "date" },
            { name: "静脉溶栓24小时内再发生颅内出血时间", code: "txtjmrs24hnzfslncxTime", tocode: "Thrombolysis24hBleedTime", value: "", type: "date" },
            { name: "介入治疗开始谈话时间", code: "txtjrzltallTime", tocode: "TreatTalkTime", value: "", type: "date" },
            { name: "介入治疗家属签字时间", code: "txtjrzlfamilySignTime", tocode: "TreatSignTime", value: "", type: "date" },
            { name: "患者到达导管室时间", code: "txtptodgRoomedTime", tocode: "CatheterArriveTime", value: "", type: "date" },
            { name: "完成动脉穿刺时间", code: "txtfinisheddmccTime", tocode: "ArteryPunctureTime", value: "", type: "date" },
            { name: "完成造影评估时间", code: "txtfinishedzypgTime", tocode: "RadiographyAssessTime", value: "", type: "date" },
            { name: "首次血管再通时间", code: "txtfristbloodaginTime", tocode: "VascularRecanalizationTime", value: "", type: "date" },
            { name: "患者离开导管室时间", code: "txtpleavedgRoomTime", tocode: "CatheterLeaveTime", value: "", type: "date" },
            { name: "血管内介入治疗24小时内再发生颅内出血时间", code: "txtxgnjrzl24hnzfslncxTime", tocode: "Catheter24hBleedTime", value: "", type: "date" },
        ]
    }
]
